﻿#include "FITKAbaInteractionManager.h"
#include "FITKAbaAbstractInteraction.h"
#include "FITKAbaAbstractStep.h"


namespace Interface {

void FITKAbaInteractionManager::deleteStepInteractions(int stepId)
{
    QList<FITKAbaAbstractInteraction*> toDelete{};
    int count = this->getDataCount();
    for (int i=0; i<count; ++i)
    {
        FITKAbaAbstractInteraction* intaction = this->getDataByIndex(i);
        if (intaction == nullptr)
            continue;
        if (intaction->getCreatedStep() == stepId)
            toDelete.append(intaction);
    }
    for (FITKAbaAbstractInteraction* i : toDelete)
    {
        this->removeDataObj(i);
    }
}

void FITKAbaInteractionManager::replaceStep(int oldStep, int newStep)
{
    int count = this->getDataCount();
    for (int i = 0; i < count; ++i)
    {
        FITKAbaAbstractInteraction* interaction = this->getDataByIndex(i);
        if (interaction == nullptr)
            continue;
        if (interaction->getCreatedStep() != oldStep)
            continue;
        interaction->setCreatedStep(newStep);
        if (!interaction->isValidInCreatedStep())
            interaction->setActiveState(false);
    }
}

}
